#pragma once

#include <QtCore/QAbstractItemModel>
#include <logger/entry.hpp>
#include <boostext/util/make_shared.hpp>




namespace Engine
{
	namespace Edit
	{
		class DocumentWindow;

		/**
		 * An ErrorModel acts both as a storage for errors as well for esposing those
		 * errors to a suitable QAbstractItemView/QListView.
		 *
		 * Errors can easily be added/removed by calling the appropriate errors.
		 */
		class ErrorModel
			: public QAbstractTableModel
		{
			Q_OBJECT

		public:

			SHARED(ErrorModel);

			/**
			 * Creates an ErrorModel.
			 *
			 * @param window   the window this model belongs to
			 */
			ErrorModel(DocumentWindow* window);
			virtual ~ErrorModel();



			/**
			 * An ErrorModel belongs to a specific DocumentWindow that is defined during object initialization.
			 * The model belongs to the window until it is destroyed.
			 *
			 * @returns the view this model belongs to
			 */
			DocumentWindow* documentWindow() const;



			/**
			 * Adds the given entry to this model.
			 */
			void add(const logger::entry& e);

			/**
			 * Removes the given entry from this model.
			 */
			void remove(const logger::entry& e);

			/**
			 * Removes all entries from this model.
			 */
			void clear();



			/**
			 * @returns the number of rows that are of the given level
			 */
			virtual int rowCount(logger::entry::Level lvl) const;




			virtual int rowCount(const QModelIndex& index = QModelIndex()) const;
			virtual int columnCount(const QModelIndex& index = QModelIndex()) const;
			virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
			virtual QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;



			/**
			 * The header data is independent of the underlying data, therefore it can be exposed through a static method.
			 */
			static QVariant _headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole);

		private:

			typedef std::vector<logger::entry>                Entries;
			typedef std::map<logger::entry::Level, QPixmap>   Icons;

			DocumentWindow*   m_window;
			Entries           m_entries;
			Icons             m_icons;
		};
		///////////////////////////////////////////////////////////////////////////////////////////
	}
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
